package com.example.week10_advanceui2;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListAdapter;

public class GridViewActivity extends AppCompatActivity {

    private int[] imageIds = {R.drawable.img_1, R.drawable.img_2, R.drawable.img_3,
            R.drawable.img_4, R.drawable.img_5, R.drawable.img_6, R.drawable.img_7,
            R.drawable.img_8, R.drawable.img_9};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view);
        GridView gridView = (GridView) findViewById(R.id.gridview);
        ImageAdapter imageAdapter = new ImageAdapter(this, imageIds);
        gridView.setAdapter(imageAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();

                switch (position) {
                    case 1://备忘录（Menu版）
                        intent.setClass(GridViewActivity.this, TextBookActivity.class);
                        startActivity(intent);
                        break;

                    case 4://备忘录（ContextMenu版）
                        intent.setClass(GridViewActivity.this, TextBookContextMenuActivity.class);
                        startActivity(intent);
                        break;

                    case 6://校园一点事（TabHost）
                        intent.setClass(GridViewActivity.this, TabHostActivity.class);
                        startActivity(intent);
                        break;

                    case 8://新闻系统（fragment）
                        intent.setClass(GridViewActivity.this, NewsActivity.class);
                        startActivity(intent);
                        break;

                }

            }
        });
    }
}
